package com.tedu.sp03.controller;

import com.tedu.sp01.entity.User;
import com.tedu.sp01.service.UserService;
import com.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class UserController {
    @Autowired
   private UserService userService;

    @GetMapping("/{userId}")  // http://localhost:8101/7
public JsonResult<User> getUser(@PathVariable Integer userId){
        User user = userService.getUser(userId);
        return JsonResult.ok().data(user);
    }
    // http://localhost:8101/7/score?score=100
    @GetMapping("/{userId}/score")
    public  JsonResult<?> addScore(@PathVariable Integer userId,Integer score){//自定义接收参数
        userService.addScore(userId, score);
    return JsonResult.ok().msg("积分添加成功");
    }
}
